<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>话费列表</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
	<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
	<meta http-equiv="refresh" content="60">
</head>
<body>
<div class="ok-body">
	<!--模糊搜索区域-->
<!--	<div class="layui-row">-->
<!--		<form class="layui-form ok-search-form">-->
<!--			<div class="layui-form-item">-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">下单时间</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<input type="text" class="layui-input" placeholder="下单时间" autocomplete="off" id="start_date" name="start_date">-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">完成时间</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<input type="text" class="layui-input" placeholder="订单完成时间" autocomplete="off" id="end_date" name="end_date">-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">原价金额</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<input type="text" class="layui-input" placeholder="原价金额" autocomplete="off" name="hmoney">-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">号码地区</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<input type="text" class="layui-input" placeholder="号码地区" autocomplete="off" name="hregion">-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">运营商</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<select name="operator" lay-verify="" lay-search>-->
<!--							<option value="" selected>请选择运营商</option>-->
<!--							<option value="1">移动</option>-->
<!--							<option value="2">联通</option>-->
<!--							<option value="3">电信</option>-->
<!--						</select>-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<label class="layui-form-label">请选择状态</label>-->
<!--					<div class="layui-input-inline">-->
<!--						<select name="hstatus" lay-verify="" lay-search>-->
<!--							<option value="" selected>请选择状态</option>-->
<!--							<option value="1">未充值</option>-->
<!--							<option value="2">已充值</option>-->
<!--							<option value="3">已退款</option>-->
<!--						</select>-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="layui-inline">-->
<!--					<div class="layui-input-inline">-->
<!--						<button class="layui-btn" lay-submit=""  lay-filter="search">搜索-->
<!--							<i class="layui-icon">&#xe615;</i>-->
<!--						</button>-->
<!--					</div>-->
<!--				</div>-->
<!--			</div>-->
<!--		</form>-->
<!--	</div>-->
	<br>
	<!--数据表格-->
	<!-- <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table> -->
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script>
	layui.use(["element", "table", "form", "laydate", "okLayer", "okUtils", "okMock","jquery"], function () {
		let table = layui.table;
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let okMock = layui.okMock;
		var $ = layui.$;
		okLoading.close();

		// laydate.render({elem: "#startTime", type: "datetime"});
		// laydate.render({elem: "#endTime", type: "datetime"});

		 table.render({
			elem: "#tableId",
			url: "/movie/sel",
			limit: 10,
			page: true,
			toolbar: "#toolbarTpl",
			size: "sm",
			cols: [[
				{type: "checkbox"},
				{field: "id", title: "ID",width: 70,align: "center"},
				{field: "yppno", title: "平台订单号",width: 70,align: "center"},
				{field: "wxphone", title: "电话号码",width: 110,align: "center"},
				// {field: "mmoney", title: "金额",width: 80,align: "center"},
				{field: "cityname", title: "城市名字",width: 160,align: "center"},
				{field: "cinemaname", title: "影院名字",width: 160,align: "center"},
				{field: "moviename", title: "电影名字",width: 80,align: "center"},
				{field: "totaluserprice", title: "电影总票价",width:110,align: "center"},
				{field: "createtime", title: "创建时间",width:110,align: "center"},
				// {field: "desc", title: "退款原因",width:110,align: "center"},
				{field: "code",
					templet: function(d) {
						if(d.code == '未充值') {
							return ' <span style="color: #d8f624;">' + d.code + '</span>'
						} else if(d.code == '已充值') {
							return ' <span style="color: #d70909;">' + d.code + '</span>'
						} else {
							return ' <span style="color: #06fa58;">' + d.code + '</span>';
						}
					},
					title: "充值状态",width: 110,align: "center"},
				{field: "number", title: "微信订单号",align: "center"},
				{title: "操作",  align: "left", templet: "#operationTpl"}
			]],

			done: function (res, curr, count) {
			}

		});
		form.on("submit(search)", function (data) {
			var result = data.field;
			table.reload('tableId',{
				// where: data.field,
				// page: {curr: curr},
				page: {
					curr: 1
				}
				, where: {
					operator: result.operator,
					hregion: result.hregion,
					hmoney: result.hmoney,
					hstatus: result.hstatus,
					end_date:result.end_date,
					start_date:result.start_date
				}
			}, 'data');

			return false;
		});

		table.on("toolbar(tableFilter)", function (obj) {
			switch (obj.event) {
				case "batchDel":
					batchDel();
					break;
			}
		});
		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {
				case "cupd":
					cupd(data.id);
					break;
				case "tupd":
					tupd(data);
					break;
				case "dupd":
					dupd(data.id);
					break;
			}
		});
		function batchDel() {
			okLayer.confirm("确定要批量删除吗？", function (index) {
				layer.close(index);
				let idsStr = okUtils.tableBatchCheck(table);
				console.log(idsStr);
				if (idsStr) {
					okUtils.ajax("/movie/dupds", "post", {idsStr: idsStr,}, true).done(function (response) {
						okUtils.tableSuccessMsg(response.msg);
						table.reload();
						return false;
					}).fail(function (error) {
						console.log(error)
					});
				}
			});
		}
		function cupd(id) {
			okLayer.confirm("确定对用户进行充值吗？", function () {
				console.log(id)
				okUtils.ajax("/movie/cupd", "post", {id: id}, true).done(function (response) {
					okUtils.tableSuccessMsg(response.msg);
					table.reload();
					return false;
				}).fail(function (error) {
					console.log(error)
				});
			})
		}
		function formatMoneyYuanToFen(yuan,digit){

			var m=0,

					s1=yuan.toString(),

					s2=digit.toString();

			try{m+=s1.split(".")[1].length}catch(e){}

			try{m+=s2.split(".")[1].length}catch(e){}

			return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)

		}
		function tupd(data) {
			okLayer.confirm("确定要退款吗？", function () {
				// console.log(data.number)
				// console.log(data.fmoney)
				// console.log("id"+data.id+",money:"+formatMoneyYuanToFen(data.totaluserprice,100),"desc")
				$.ajax({url:"http://localhost:8080/refund",type:"POST",dataType:'xml',data:{orderNum:data.number,money:formatMoneyYuanToFen(data.totaluserprice,100),desc:''},success:function (res){
						console.log(res);
						var return_code = $("return_code", $(res)).text();
						var return_msg = $("return_msg", $(res)).text();
						if (return_code=="SUCCESS"&&return_msg=="OK"){
							okUtils.ajax("/movie/tupd", "post", {id: data.id}, true).done(function (response) {
								okUtils.tableSuccessMsg(response.msg);
								table.reload();
								return false;
							}).fail(function () {
								okUtils.tableSuccessMsg(response.msg);
								table.reload();
								return false;
							});
						}
					}}
				)

			})
		}
		function dupd(id) {
			okLayer.confirm("确定对用户进行删除吗？", function () {
				okUtils.ajax("/movie/dupd", "post", {id: id}, true).done(function (response) {
					okUtils.tableSuccessMsg(response.msg);
					table.reload();
					return false;
				}).fail(function (error) {
					console.log(error)
				});
			})
		}
	})
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<div class="layui-btn-container">
		<div class="layui-inline" lay-event="batchDel"><i class="layui-icon layui-icon-delete"></i></div>
	</div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	{{#  if(d.code == '发货失败'){ }}
<!--	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="cupd">确认待缴</a>-->
	<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="tupd">退款</a>
	{{#  } else if(d.code == '已完成') { }}
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dupd">删除</a>
	{{#  } else if(d.code == '已退款') { }}
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dupd">删除</a>
	{{#  } }}
</script>
</body>
</html>
